[#ftl]
import { ApolloQueryResult, FetchResult, FetchPolicy } from '@apollo/client/core';
import {MutationResult} from "apollo-angular";
import { Observable } from 'rxjs';
[#list importTypes as imp]
${imp}
[/#list]
/**************************************************************************************
 * ${serviceInfo.comment}
 */
/*************************************************************************************
 * 服务接口定义
 */

export interface ${serviceInfo.modelName}Number{
  value:number;
}
export interface ${serviceInfo.modelName}String{
  value:string;
}
export interface ${serviceInfo.modelName}Boolean{
  value:boolean;
}

export interface ${serviceInfo.name}Api {
  [#list serviceInfo.queries.keySet() as qkey][#assign query=serviceInfo.queries[qkey]]
  ${query.name}([#if query.params?size gt 0]variables: ${serviceInfo.name}_${query.name}Variables, options:${serviceInfo.name}QueryOptions[/#if]): Observable<ApolloQueryResult<${serviceInfo.name}_${query.name}Result>>; // ${query.comment}
  [/#list]
      [#list serviceInfo.mutations.keySet() as qkey][#assign mutation=serviceInfo.mutations[qkey]]
  ${mutation.name}([#if mutation.params?size gt 0]variables: ${serviceInfo.name}_${mutation.name}Variables[/#if]): Observable<MutationResult<${serviceInfo.name}_${mutation.name}Result>>; // ${mutation.comment}
  [/#list]
}
export interface ${serviceInfo.name}QueryOptions{
  cachePolicy:FetchPolicy;
  more:boolean;
}
[#list serviceInfo.queries.keySet() as qkey][#assign query=serviceInfo.queries[qkey]]

/**
 * ${query.comment}
 */
export interface ${serviceInfo.name}_${query.name}Result{
    ${serviceInfo.beanName}_${query.name}: ${returnMap(query)};
}
[#if query.params?size gt 0]
export interface ${serviceInfo.name}_${query.name}Variables{
    [#list query.params as param]
      ${paramMap(param)}; // ${param.comment}
    [/#list]
}
  [/#if]
[/#list]

  [#list serviceInfo.mutations.keySet() as qkey][#assign mutation=serviceInfo.mutations[qkey]]

export interface ${serviceInfo.name}_${mutation.name}Result{
  ${serviceInfo.beanName}_${mutation.name}: ${serviceInfo.modelName}MutationInfo;
}
  [#if mutation.params?size gt 0]

/**
 * ${mutation.comment}
 */
export interface ${serviceInfo.name}_${mutation.name}Variables{
  [#list mutation.params as param]
    ${paramMap(param)}; // ${param.comment}
    [/#list]
}
      [/#if]
        [/#list]
/**
 * 错误信息
 */
export interface ${serviceInfo.modelName}ErrorBody {
  message: string;
  stackTrace: string;
}

/**
 * 查询结果信息
 */
export interface ${serviceInfo.modelName}ResultInfo {
  totalCount: number;
  queryTime: number;
  sign: string;
  message: string;
}

/**
 * 分页信息
 */
export interface ${serviceInfo.modelName}PageInfo{
  page: number;
  size: number;
  offset: number;
  endCursor: string;
  hasNextPage: boolean;
}

/**
 * 查询集合返回对象
 */
export interface  ${serviceInfo.modelName}Connection{
  resultInfo: ${serviceInfo.modelName}ResultInfo;
  edges: ${serviceInfo.viewName}Edge[];
  pageInfo: ${serviceInfo.modelName}PageInfo;
  uuid: string;
}
export interface ${serviceInfo.viewName}Edge{
  node:${serviceInfo.viewName};
}
/**
 * 查询单个对象返回结果
 */
export interface ${serviceInfo.modelName}Package{
  resultInfo: ${serviceInfo.modelName}ResultInfo;
  entity: ${serviceInfo.viewName};
  uuid: string;
}

/**
 * 排序类型
 */
export interface ${serviceInfo.modelName}OrderBy {
  field: string;
  type: 'ASC' | 'DESC';
}

/**
 * 更新返回结果信息
 */
export interface ${serviceInfo.modelName}MutationInfo {
  status: boolean;
  rows: number;
  messages: string;
  uuid: string;
  sign: string;
  executeTime: number;
  result: ${serviceInfo.viewName};
  errorBody: ${serviceInfo.modelName}ErrorBody;
}

/**
 * 字符串筛选接口
 */
export interface ${serviceInfo.modelName}StringFilter {
  eq?: string;
  neq?: string;
  like?: string;
  in?: string[];
  nin?: string[];
  gt?: string;
  lt?: string;
  gte?: string;
  lte?: string;
}

/**
 * 数字过滤条件接口
 */
export interface ${serviceInfo.modelName}NumberFilter {
  eq?: number;
  neq?: number;
  in?: number[];
  nin?: number[];
  gt?: number;
  lt?: number;
  gte?: number;
  lte?: number;
}

/**
 * 布尔类型删选接口
 */
export interface ${serviceInfo.modelName}BooleanFilter {
  eq?: boolean;
  neq?: boolean;
}

[#macro viewField name]
    [#if serviceInfo.types[name]??]
  [#list serviceInfo.types[name].fields as field]
      ${field.name}[#if field.workerType.name()=="STORE_ENTITY"||field.workerType.name()=="VIEW_ENTITY"||field.workerType.name()=="INPUT_ENTITY"]_id[#elseif field.workerType.name()=="API_ENTITY"||field.workerType.name()=="LIST_API_ENTITY"]
        {
          [@viewField name=typeSimpleName(field.typeName)/]
        }[/#if]
      [/#list]
    [/#if]
      [/#macro]



/*****************************************************************************************
 * 查询接口
 */
export const ${serviceInfo.beanName}Query = {
  [#list serviceInfo.queries.keySet() as qkey][#assign query=serviceInfo.queries[qkey]][#if qkey_index!=0],[/#if] // ${query.comment}
  ${serviceInfo.beanName}_${query.name}: `${serviceInfo.beanName}_${query.name}[#if query.params?size gt 0]([#list query.params as param][#if param_index!=0],[/#if]${param.name}:$${param.name}[/#list])[/#if][#if query.result.name()=="LIST_VIEW_ENTITY"||query.result.name()=="VIEW_ENTITY"]{
    resultInfo{
      totalCount
      queryTime
      sign
      message
    }
    [#if query.result.name()=="LIST_VIEW_ENTITY"]
    edges{
      node{
          [@viewField name=serviceInfo.viewName/]
        }
    }
    pageInfo{
      page
      size
      offset
      hasNextPage
      endCursor
    }
    [#elseif query.result.name()=="VIEW_ENTITY"]
    entity{
      [@viewField name=serviceInfo.viewName/]
    }
    [/#if]
    uuid
  }[#else]{value}[/#if]`
  [/#list]
};

/*********************************************************************
 * 更新接口信息
 */
export const ${serviceInfo.beanName}Mutation = {
  [#list serviceInfo.mutations.keySet() as mkey][#assign mutation=serviceInfo.mutations[mkey]][#if mkey_index!=0],[/#if] // ${mutation.comment}
  ${serviceInfo.beanName}_${mutation.name}: `${serviceInfo.beanName}_${mutation.name}[#if mutation.params?size gt 0]([#list mutation.params as param][#if param_index!=0],[/#if]${param.name}:$${param.name}[/#list])[/#if]{
    status
    rows
    messages
    uuid
    sign
    executeTime
    [#if mutation.result.name()=="LIST_VIEW_ENTITY"||mutation.result.name()=="VIEW_ENTITY"]
    result{
      [@viewField name=serviceInfo.viewName/]
    }[/#if]
    errorBody{
      message
      stackTrace
    }
  }`
    [/#list]
};

/************************************************************************
 * 类型信息
 */
[#list (serviceInfo.types.keySet()) as key]
[#assign type=serviceInfo.types[key]]
/**
 * ${type.comment}
 */
export interface ${type.name} {
  [#list type.fields as field]
  ${field.name}${(field.workerType.name() == "STORE_ENTITY"||field.workerType.name() == "INPUT_ENTITY"||field.workerType.name() == "VIEW_ENTITY"||field.workerType.name() == "FILTER_ENTITY") ? then("_id","")}${(field.required&&type.workerEntityType.name()!="FILTER")?then("","?")}: ${(type.workerEntityType.name()=="FILTER")?then(serviceInfo.modelName+filterMap(field),typeMap(field))}; // ${field.comment}
  [/#list]
  [props: string]: any;
}
[/#list]
